var profile = lottie.loadAnimation({
    container: $("#profile")[0],
    path: "/asset/mine-purple.json",
    loop: true,
    render: "canvas",
    autoplay: true
});

var register = new Vue({
    el: "#container",
    data: {
        phone: "",
        loginId: "",
        loginPwd: "",
        userName: "",
        termOfService: false
    },
    methods: {
        submit: function () {
            let vm = this;
            if (!vm.termOfService) {
                layer.msg("请同意用户协议！");
                return;
            }
            $.ajax({
                type: "POST", //默认get
                url: "/user/register", //默认当前页
                data: vm.$data, //格式{key:value}
                dataType: "json",
                success: function (response) {
                    //请求成功回调
                    if (response.code == 0) {
                        location.href = "/user/loginPage";
                        return;
                    }
                    layer.alert(response.msg);
                },
                error: function (e) {
                    //请求超时回调
                    if (e.statusText == "timeout") {
                        layer.alert("请求超时");
                    }
                }
            });
        },
        redirectToLogin: function () {
            location.href = "/user/loginPage";
        },
        verifyPhone: function () {
            var vm = this;
            if (vm.phone.length !== 11) {
                layer.tips("电话号码为11位", "#phone");
            }
        },
        verifyLoginId: function () {
            var vm = this;
            var loginId = vm.loginId;
            if (loginId.length === 0 || loginId == null) {
                layer.tips("请填写用户账号", "#loginId");
            } else if (loginId.length < 6) {
                layer.tips("用户账号长度小于6","#loginId");
            } else if (loginId.length > 16) {
                layer.tips("用户账号长度应小于16位", "#loginId");
            }
        },
        verifyUserName: function () {
            var vm = this;
            var userName = vm.userName;
            if (userName.length === 0 || userName == null) {
                layer.tips("请填写昵称", "#userName");
            }
        },
        verifyPassword: function () {
            var vm = this;
            var password = vm.loginPwd;
            if (password.length === 0 || password == null) {
                layer.tips("请输入密码","#password");
            } else if (password.length < 6) {
                layer.tips("密码长度需大于6","#password")
            } else if (password.length > 20) {
                layer.tips("密码长度应小于20", "#password");
            }
        }
    }
});
